package com.example.myapplication;

import android.content.Intent;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;

import com.example.beans.PaperInformation;
import com.example.fragment.AdviceFragment;
import com.example.fragment.GradeFragment;
import com.example.fragment.PaperInfoadviceFragment;
import com.example.fragment.WorkInfoadviceFragment;
import com.example.inter.AdapterCallback;
import com.example.inter.FragmentCallback;

public class AnswerActivity extends AppCompatActivity implements View.OnClickListener {

    private WorkInfoadviceFragment workInfoadviceFragment;
    private PaperInfoadviceFragment paperInfoadviceFragment;
    private PaperInformation paperInformation;
    private RecyclerView recyclerView;
    private LinearLayoutManager layoutManager;
    private AdviceFragment adviceFragment;
    private GradeFragment gradeFragment;
    private String Tag;
    public FragmentCallback fragmentCallBack;
    public FloatingActionButton fab;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_answer);
        initView();
        fab.setOnClickListener(this);
        // workInfoadviceFragment = new WorkInfoadviceFragment();
        paperInfoadviceFragment = new PaperInfoadviceFragment();
        gradeFragment = new GradeFragment();
        adviceFragment = new AdviceFragment();
        Bundle bundle = getBundle();
        paperInfoadviceFragment.setArguments(bundle);
        //      workInfoadviceFragment.setArguments(bundle);
        adviceFragment.setArguments(bundle);
        gradeFragment.setArguments(bundle);
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        //     fragmentTransaction.add(R.id.workinfo,workInfoadviceFragment,"workinfo");
        fragmentTransaction.add(R.id.Linear_paper_info, paperInfoadviceFragment, "paperinfo");
        fragmentTransaction.add(R.id.grade,gradeFragment,"grade");
        fragmentTransaction.add(R.id.Linear_advice, adviceFragment, "advice");
        //      fragmentTransaction.show(workInfoadviceFragment);
        fragmentTransaction.show(paperInfoadviceFragment);
        fragmentTransaction.show(adviceFragment);
        fragmentTransaction.commit();

    }

    public Bundle getBundle() {
        paperInformation = getInfo();
        String workid = paperInformation.getWorkid();
        String paper_id = paperInformation.getPaper_id();
        Bundle bundle = new Bundle();
        bundle.putString("workid", workid);
        bundle.putString("paper_id", paper_id);
        bundle.putString("paperId",paper_id);
        return bundle;
    }


    public PaperInformation getInfo() {

        return (PaperInformation) getIntent().getExtras().getSerializable("userinfo");

    }

    public void initView() {

        fab = (FloatingActionButton) findViewById(R.id.fab);
    }


    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.fab:
                Bundle bundle = getBundle();
                Intent intent = new Intent();
                intent.putExtras(bundle);
                intent.setClass(this,AdviceActivity.class);
                startActivity(intent);
                break;
        }


    }
}
